
/**
* COOKIE存储
* @param {String} key 键
* @param {Object} val 值
* @param {Number} time 时间，默认10s
*/

console.log('------------------------setcookis--------------------------------');
function setcookie(key, val, time) {
    const t = new Date
    t.setTime(t.getTime() - 1000 * 60 * 60 * 8 + time * 1000)
    console.log(t);
    document.cookie = `${key}=${val}; expires=${t}`
}


/**
 * COOKIE删除
 * @param {String} key 键
 * @returns undefined
 */

 console.log('-------------------------removecookie------------------------------');

function removecookie(key) {
    setcookie(key, null, -1)
}

// removecookie(name)


/**
 * COOKIE获取
 * @param {String} key 键
 * @returns String
 */

 console.log('----------------------------getcookie----------------------------');

function getcookie(key) {
    let temp = document.cookie.split('; ')
    for (let i = 0; i < temp.length; i++) {
        let newtemp = temp[i].split('=')
        if (key === newtemp[0]) {
            return newtemp[1]
        }
    }
}